import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: {title: '首页', icon: 'dashboard', affix: true}
    }]
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('@/views/register/register'),
    hidden: true,
    meta: {requiresAuth: false}
  },
  {
    path: '/detail',
    name: 'Detail',
    component: () => import('@/views/Detail/Detail'),
    hidden: true,
    meta: {requiresAuth: false}
  },
  {
    path: '/change_Password',
    name: 'Change_Password',
    component: () => import('@/views/Change_Password/Change_Password'),
    hidden: true,
    meta: {requiresAuth: false}
  },
  {
    path: '/test',
    name: 'test',
    component: () => import('@/views/test'),
    hidden: true,
    meta: {requiresAuth: false}
  }
];

export const routers = [
  {
    menuId: 4,
    type: 'normal',
    component: "Layout",
    path: "/test",
    redirect: "/test/test1",
    name: "test",
    title: "系统功能",
    icon: "form",
    parentId: 0,
    isLeaf: "N",
    hidden: false,
    children: [
      {
        menuId: 11,
        component: "test/bodyManage",
        path: "bodyManage",
        redirect: null,
        name: "bodyManage",
        title: "身体信息管理",
        icon: "el-icon-s-check",
        parentId: 4,
        isLeaf: "Y",
        hidden: false,
        meta: {
          icon: "el-icon-s-check",
          title: "身体信息管理"
        }
      },
      {
        menuId: 7,
        type: 'normal',
        component: "test/test3",
        path: "test3",
        redirect: "",
        name: "test3",
        title: "运动知识",
        icon: "el-icon-s-opportunity",
        parentId: 4,
        isLeaf: "Y",
        hidden: false,
        meta: {
          icon: "el-icon-s-opportunity",
          title: "运动知识"
        }
      },
      {
        menuId: 8,
        type: 'normal',
        component: "test/HealthKnowledgeView",
        path: "health",
        redirect: "",
        name: "health",
        title: "健康知识",
        icon: "el-icon-s-opportunity",
        parentId: 4,
        isLeaf: "Y",
        hidden: false,
        meta: {
          icon: "el-icon-s-opportunity",
          title: "健康知识"
        }
      },
      {
        menuId: 6,
        type: 'normal',
        component: "test/test2",
        path: "test2",
        redirect: "",
        name: "test2",
        title: "健康评估",
        icon: "el-icon-first-aid-kit",
        parentId: 4,
        isLeaf: "Y",
        hidden: false,
        meta: {
          icon: "el-icon-first-aid-kit",
          title: "健康评估"
        }
      },
      {
        menuId: 20,
        type: 'normal',
        component: "test/Goals",
        path: "goals",
        redirect: "",
        name: "goals",
        title: "健康目标管理",
        icon: "el-icon-first-aid-kit",
        parentId: 4,
        isLeaf: "Y",
        hidden: false,
        meta: {
          icon: "el-icon-first-aid-kit",
          title: "健康目标管理"
        }
      },
      {
        menuId: 5,
        type: 'normal',
        component: "test/test1",
        path: "test1",
        redirect: "",
        name: "test1",
        title: "身体信息上传",
        icon: "form",
        parentId: 4,
        isLeaf: "Y",
        hidden: false,
        meta: {
          icon: "form",
          title: "身体信息上传"
        }
      }
    ],
    meta: {
      icon: "form",
      title: "系统功能"
    }
  },
  {
    menuId: 1,
    component: "Layout",
    path: "/sys",
    redirect: "/sys/user",
    name: "sysManage",
    title: "系统管理",
    icon: "el-icon-s-order",
    parentId: 0,
    isLeaf: "N",
    hidden: false,
    children: [
      {
        menuId: 10,
        component: "sys/userBodyManage",
        path: "userBodyManage",
        redirect: null,
        name: "userBodyManage",
        title: "用户身体信息管理",
        icon: "el-icon-s-check",
        parentId: 1,
        isLeaf: "Y",
        hidden: false,
        meta: {
          icon: "el-icon-s-check",
          title: "用户身体信息管理"
        }
      },
      {
        menuId: 9,
        component: "sys/DetailsManage",
        path: "DetailsManage",
        redirect: null,
        name: "DetailsManage",
        title: "运动详情管理",
        icon: "el-icon-s-check",
        parentId: 1,
        isLeaf: "Y",
        hidden: false,
        meta: {
          icon: "el-icon-s-check",
          title: "运动详情管理"
        }
      },
      {
        menuId: 8,
        component: "sys/sportDetails",
        path: "sportDetails",
        redirect: "",
        name: "sportDetails",
        title: "运动知识管理",
        icon: "el-icon-s-opportunityel-icon-s-custom",
        parentId: 1,
        isLeaf: "Y",
        hidden: false,
        meta: {
          icon: "el-icon-s-opportunityel-icon-s-custom",
          title: "运动知识管理"
        }
      },
      {
        menuId: 3,
        component: "sys/notice",
        path: "notice",
        redirect: null,
        name: "noticeList",
        title: "通知公告管理",
        icon: "el-icon-user",
        parentId: 1,
        isLeaf: "Y",
        hidden: false,
        meta: {
          icon: "el-icon-user",
          title: "通知公告管理"
        }
      },
      {
        menuId: 4,
        component: "sys/HealthKnowledge",
        path: "health-knowledge",
        redirect: null,
        name: "HealthKnowledge",
        title: "健康知识管理",
        icon: "el-icon-user",
        parentId: 1,
        isLeaf: "Y",
        hidden: false,
        meta: {
          icon: "el-icon-user",
          title: "健康知识管理"
        }
      },
      {
       menuId: 2,
       component: "sys/user",
       path: "user",
       redirect: null,
       name: "userList",
       title: "用户管理",
       icon: "user",
       parentId: 1,
       isLeaf: "Y",
       hidden: false,
       meta: {
          icon: "user",
          title: "用户管理"
        }
      }
    ],
    meta: {
      icon: "el-icon-s-order",
      title: "系统管理"
    }
  }
]


const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({y: 0}),
  mode: "history",
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
